import { UserProfilesAPI } from '@/request/api'
export default {
    namespaced: true,
    //共享数据
    state: {
        userInfo: {
            nickName: '',
            coin: 0,
            headImg: require('../../assets/img/userImg.f8bbec5e.png')
        },
        cartTotal: 0
    },
    mutations: {
        changeUserInfo(state, payload) {
            state.userInfo = payload.userInfo;
            state.cartTotal = payload.cartTotal;
        },
        initUserInfo(state) {
            state.userInfo = {
                nickName: '',
                coin: 0,
                headImg: require('../../assets/img/userImg.f8bbec5e.png')
            }
            state.cartTotal = 0
        }
    },
    actions:{
        async asyncChangeUserInfo(context) {
            let user = await UserProfilesAPI();
            context.commit("changeUserInfo", user.data)
        }
    }
}